<script>
	import {
		useSocketStore,
	} from '@/stores/socket';
	import {
		throttle,
	} from '@/utils/index';
	export default {
		onLaunch: function(msg) {
			// #ifdef APP-PLUS
			plus.screen.lockOrientation("portrait-primary"); // 设置为竖屏
			plus.navigator.setStatusBarStyle("dark"); // dark/light
			// #endif
			
			this.safeareaBottom("#f7f7f7");

			uni.$once('plus-nav-close', () => {
				// #ifdef APP-PLUS
				// 跳转完页面后再关闭启动页
				plus.navigator.closeSplashscreen();
				// #endif
			})

			uni.onTabBarMidButtonTap(throttle(() => {
				uni.navigateTo({
					url: '/pages/sendDynamic/sendDynamic',
					animationType: "slide-in-bottom",
				});
			}));

			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide')
		},
		onUnload: function() {
			console.log('App onUnload')
		},
		// 捕获 app error
		onError(err) {
			console.log(err)
		},
		methods: {
			/**
			 * 开启心跳检测
			 */
			_heartbeat() {
				let socket = useSocketStore();
				try {
					socket.send({
						type: 9,
						info: "ping······",
					});
					socket.heartbeatInterval = setInterval(() => {
						socket.send({
							type: 9,
							info: "ping······",
						});
					}, socket.timeout);
				} catch (e) {
					throw Error(e);
				}
			},
			/**
			 * 修改底部安全区颜色
			 */
			safeareaBottom(colors) {
				// #ifdef APP-PLUS
				let color, ac, c2int, win;
				color = plus.android.newObject("android.graphics.Color")
				ac = plus.android.runtimeMainActivity();
				c2int = plus.android.invoke(color, "parseColor", colors);
				win = plus.android.invoke(ac, "getWindow");
				plus.android.invoke(win, "setNavigationBarColor", c2int)
				// #endif
			},
			/**
			 * 功能暂未开发提示
			 */
			funNone() {
				uni.showToast({
					title: '功能正在开发中',
					duration: 2000,
					position: 'top',
				});
			},
		}
	}
</script>

<style lang='scss'>
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-plus/index.scss";

	/*每个页面公共css */
	.bg-color {
		background-color: #5a5ad6;
	}

	/* 内容content flex布局 */
	.content_vue {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	/* 绝对定位 铺满 */
	.positionA {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
	}
</style>
